-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variable iterator overrides #31809
Conversation
Allows usage of optimized underlying implementations if any OS supports them.
Will allow optimised usage of `count` now and `nth` & `last` if `IntoIter` ever gets them in the future.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
inner: EnvSlices, | ||
} | ||
|
||
struct EnvSlices { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me when I initially read this it wasn't clear why the separation here was needed, could you add a comment explaining why these are separate?
Could you add some tests as well which exercise these functions? |
@alexcrichton done. Again I could only type check the tests as I don't have a windows machine setup for rust dev. I hope using the type alias for |
Ah that may be an extra layer or two of indirection which may not be worth it, perhaps just Also, could you move the tests so they cover both the Unix and Windows cases? That should also help exercise the implementation in terms of what's actually being run with |
} else { | ||
let status = Command::new(env::current_exe().unwrap()) | ||
.arg("empty") | ||
.env_clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may or may not pass on Windows due to #31259
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, that is... annoying 😦
Ok, this looks good to me, could you also squash the commits together? |
Avoids doing the [u16] -> OsString conversion when we don't care about using the env vars.
073e9ec
to
52d506e
Compare
⌛ Testing commit 52d506e with merge 9e16bea... |
@bors: retry force |
⌛ Testing commit 52d506e with merge ce41c0e... |
💔 Test failed - auto-linux-64-x-android-t |
Closing due to inactivity, but feel free to reopen with tests fixed! |
For case #24214, additional iterators mentioned in #24214 (comment).
Overrides
std::env::{ Vars, VarsOs }::{ count, nth, last}
to proxy through to their inner iterator (would be nice if there were some iterator wrapper trait that meant these didn't need to be implemented every time an iterator was wrapped...).Overrides
std::sys::unix::os::Env::{ count, nth, last }
to proxy through to the innervec::IntoIter
. Should makecount
faster, and future proofs in caselast
ornth
get optimised implementations in the future.Overrides
std::sys::windows::Env::{ count, nth, last }
to not allocateOsString
s when not needed. Done by defining a sub-iterator that returns the raw pointers and lengths, this uses the default implementations as they should be pretty much equivalent to manually implemented versions, then in the outer iterator does the allocation with the result.I don't have a machine I can actually test the windows changes on, with some hackery (https://gist.github.com/Nemo157/0d1f02b08c132f1a00da) I managed to get the type checker at least running to ensure it should compile. It would be nice if there were some way to test the higher level platform specific code. As far as I can tell testing
windows::Env
on unix would work fine if the infrastructure was setup for it.